<?php # Превью акции и новости на главной странице
class preview_akcion_and_news extends Load_use
{
	function getBlock()
	{
		$html = $html_list = '';
		$akcii_news = array( 'akcii_item' => array( 'url' => 'akcii', 'dir' => 'akcions_image', 'title' => 'Акции',   'title2' => 'Все акции' ),
							 'news_item'  => array( 'url' => 'news',  'dir' => 'news_image',    'title' => 'Новости', 'title2' => 'Все новости' ) );
		
		foreach( $akcii_news as $templ => $data )
		{
			$this->conn->query('
				SELECT p.url, p.title, p.text1, pa.params
					FROM pages AS p 
						LEFT JOIN pages_attachments AS pa on pa.page_id = p.id AND pa.name = "'.$data['dir'].'" 
							WHERE p.templ = "'.$templ.'" 
								ORDER BY `date_create` DESC
									LIMIT 1' );
									
			$row = $this->conn->fetch();
			$img = unserialize( $row->params );
			$img = $img ? $GLOBALS['load']->module('imager','getThumbName',array('original_name'=>'/inc/images/'.$data['url'].$img['0'], 'size'=> 'h' ) ) : '';
			
			$html_list .= '	<li>
								<div class="global-photo">
									<a href="/'.$data['url'].'/'.$row->url.'"><img src="'.$img.'" alt="" /></a>
								</div>
								<div class="shares-and-news__description">
									<h3 class="big-title">'.$data['title'].'</h3>
									<p>'.$row->text1.'</p>
									<a href="/'.$data['url'].'">'.$data['title2'].'</a>
								</div>
							</li>';
		}
		return '<ul class="shares-and-news">
					'.$html_list.'
				 </ul>';
	}
}